package com.kly.manager.ai;

import io.reactivex.Scheduler;
import io.reactivex.schedulers.Schedulers;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author admin
 * @date 2025/4/28
 */
@Configuration
public class AIConfig {


    /**
     * 获取scheduler
     */
    @Bean
    public Scheduler scheduler() {
    //     创建线程工厂
        ThreadFactory threadFactory = new ThreadFactory() {
            final AtomicInteger count = new AtomicInteger(1);
            @Override
            public Thread newThread(@NotNull Runnable r) {
                return new Thread(r, "thread-" + count.getAndIncrement());
            }
        };
    //     创建线程池
        ExecutorService executor = new ScheduledThreadPoolExecutor(10, threadFactory);
        return Schedulers.from(executor);
    }
}
